<template>
	<view class="content">
		<image src="../../static/home/home-bg.png" mode="widthFix" class="top-img"></image>
		<view class="top">
			<view class="news-block">
				<view class="news-list">
					<view class="login">
						<view class="login-item">
							<image src="../../static/home/mine-log.png" class="login-img"></image>
							<view class="FangZhengHanZhenGuangBiaoJianTi title">
								{{user.userName.length>0?user.userName:'微信用户'}}
							</view>
						</view>
						<button class="btn" v-if="!user.mobile.length>0" open-type="getPhoneNumber"
							@getphonenumber="getPhoneNumber">登录</button>
						<view v-else class="revise-item" @click="navigate('/pages/mine/info/index')">
							<view class="revise">修改个人信息</view>
							<image src="../../static/mine/more.png" style="width: 40rpx; height: 40rpx;">
							</image>
						</view>
					</view>
					<view class="notice">
						<view class="title-item">
							<image src="../../static/home/notice.png" class="notice-img"></image>
							<view class="thread"></view>
						</view>
						<view class="notice swiper-item">
							<swiper autoplay="true" class="notice-list" vertical="true" interval="8000">
								<swiper-item v-for="(item,index) in newsList" :key="item.id" :item-id="item.id"
									class="notice-item"
									@click="navigate('/pages/lighthouse/detail?id='+item.id+'&type=1')">
									<view class="news">{{item.title}}</view>
								</swiper-item>
							</swiper>
						</view>
					</view>
				</view>
			</view>
			<view class="menu-item" @click="navigate('/pages/index/complaint/index')">
				<image src="/static/home/complaint.png" class="menu-img" mode="widthFix"></image>
				<view class="title">我要投诉</view>
			</view>
			<view class="menu-block">
				<view class="menu-item" @click="navigate('/pages/lighthouse/index')">
					<image src="/static/home/lighthouse.png" class="menu-img" mode="widthFix"></image>
					<view class="title">曝光台</view>
				</view>
				<view class="menu-item" @click="navigate('/pages/index/progress-query/index')">
					<image src="/static/home/progress.png" class="menu-img" mode="widthFix"></image>
					<view class="title">进度查询</view>
				</view>
			</view>
			<view class="info-item">
				<view class="tip">提示</view>
				<view class="text">
					本平台为肃州区劳动保障监察大队的线上通道，为广大劳动者提供欠薪反映、办理查询等便捷服务，高效维护劳动者合法权益。您也可以直接拨打务工所在地劳动监察部门投诉电话直接投诉。</view>
				<view class="call-item">肃州区劳动保障监察大队：0937-2663736
					<image src="../../static/home/call.png" class="call-img" mode="widthFix" @click="callPhone"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		loginApi,
		getNewsListApi,
		addBrowseApI
	} from '@/api/login.js'
	import {
		getStorage,
		setStorage
	} from '@/util/auth.js';
	import {
		showToast
	} from '@/util/util.js'
	export default {
		data() {
			return {
				newsList: [],
				user: {
					userName: '',
					mobile: '',
				}
			}
		},
		methods: {
			//onShareAppMessage 分享给朋友
			//onShareTimeline  分享到朋友圈
			// #ifdef MP
			onShareAppMessage: function(res) {
				if (res.from === 'button') {
					// 来自页面内转发按钮
					console.log(res.target)
				}
				return {
					path: '/pages/index/index'
				}
			},
			// #endif
			onShareTimeline(res) {
				let distSource = uni.getStorageSync('distSource');
				if (distSource) {
					return {
						//title: this.list.jobTitle,
						path: '/pages/index/index',
						type: 0,
						query: 'id=' + distSource,
					}
				}
			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			callPhone() {
				uni.makePhoneCall({
					phoneNumber: '0937-5933710',
					success() {
						console.log('拨打成功了');
					},
					fail() {
						console.log('拨打失败了');
					}
				})
			},
			getPhoneNumber(e) {
				if (!e.detail.code) {
					showToast('取消了授权');
					return;
				}
				uni.showLoading({
					title: '提交中',
					mask: true,
				})
				const mobileCode = e.detail.code
				wx.login({
					success: (login) => {
						const code = login.code;
						loginApi({
							mobileCode: mobileCode,
							code: code
						}).then((res) => {
							uni.hideLoading()
							const loginInfo = {
								token: res.token,
								...res.user
							};
							this.user = res.user
							setStorage('login', loginInfo, 604800);
							showToast('登录成功');
						})
					}
				})
			},
			getNewsList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getNewsListApi().then(data => {
					uni.hideLoading()
					this.newsList = data;
				})
			},
			addBrowse() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				addBrowseApI().then(data => {
					uni.hideLoading()
				})
			}
		},
		onShow() {
			const loginInfo = getStorage('login');
			if (loginInfo) {
				this.user = loginInfo
			}
		},
		onLoad() {
			this.getNewsList()
			this.addBrowse()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		min-height: 100vh;

		.top-img {
			width: 100%;
		}

		.top {
			display: flex;
			flex-direction: column;
			//width: 100%;
			background: #fff;
			margin-top: -70rpx;
			border-radius: 60rpx;
			position: relative;
			padding: 30rpx;
			background: #F6F6F6;

			.news-block {
				margin-top: -140rpx;

				.news-list {
					background: rgba(255, 255, 255, 0.8);
					backdrop-filter: blur(3px);
					border-radius: 20rpx;
					box-shadow: 0 0 10px 0 #dedede;
					padding: 30rpx;

					.login {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						border-bottom: 1px solid #d4d3d3;
						align-items: center;
						height: 80rpx;

						.login-item {
							display: flex;
							flex-direction: row;
							align-items: center;

							.login-img {
								width: 50rpx;
								height: 55rpx;
								margin-right: 10rpx;
							}

							.title {
								//font-weight: bold;
								font-size: 40rpx;
							}
						}


						.btn {
							width: 240rpx;
							height: 65rpx;
							border-radius: 40rpx;
							background: #027BFD;
							color: #fff;
							display: flex;
							justify-content: center;
							align-items: center;
							margin-bottom: 15rpx;
							margin-right: 0rpx;
							font-size: 30rpx;
						}

						.revise-item {
							display: flex;
							flex-direction: row;
							align-items: center;

							.revise {
								color: #027BFD;
								font-size: 30rpx;
							}
						}
					}

					.notice {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						height: 70rpx;
						align-items: center;
						margin-top: 20rpx;

						.title-item {
							display: flex;
							flex-direction: row;
							align-items: center;
							margin-left: 5px;

							.notice-img {
								width: 160rpx;
								height: 46rpx;
							}

							.thread {
								margin-left: 25rpx;
								width: 4rpx;
								height: 40rpx;
								border-radius: 4rpx;
								background-image: linear-gradient(#fff, #027BFD, #fff);
							}

							.title {
								font-weight: bold;
								font-size: 42rpx;
								color: #027BFD;
								margin-right: 10rpx;

							}

							.text {
								background: #027BFD;
								color: #fff;
								font-size: 40rpx;
								margin-right: 30rpx;

							}
						}

						.notice.swiper-item {
							height: 60rpx;
							//border-left: 1.5px solid #027BFD;
							margin-top: 0;

							.notice-list {
								color: #027BFD;
								width: 420rpx;
								height: 60rpx;
								margin-left: 10rpx;

								.notice-item {
									height: 60rpx;
									display: flex;
									align-items: center;

									.news {
										overflow: hidden;
										text-overflow: ellipsis;
										white-space: nowrap;
									}
								}

							}
						}
					}
				}
			}

			.menu-item {
				//width: calc((100% - 30rpx) / 2);
				margin-bottom: 30rpx;
				margin-top: 30rpx;

				.menu-img {
					width: 100%;
					position: relative;
				}

				.title {
					margin-top: -124rpx;
					position: relative;
					display: flex;
					justify-content: center;
					padding-left: 100rpx;
					color: #fff;
					font-size: 38rpx;
					font-weight: bold;
				}
			}

			.menu-block {
				display: flex;
				margin-top: 30rpx;

				.menu-item {
					width: calc((100% - 30rpx) / 2);
					margin-right: 30rpx;

					.menu-img {
						width: 100%;
						position: relative;
					}

					.title {
						margin-top: -124rpx;
						position: relative;
						display: flex;
						justify-content: flex-end;
						padding-right: 40rpx;
						color: #fff;
						font-size: 38rpx;
						font-weight: bold;
					}
				}

				.menu-item:last-child {
					margin-right: 0;
				}
			}

			.info-item {
				margin-top: 100rpx;
				width: 100%;
				border-radius: 30rpx;
				line-height: 60rpx;
				background: url('../../static/home/bg1.png');
				margin-bottom: 40rpx;

				.tip {
					text-align: center;
					font-size: 38rpx;
					margin-top: 30rpx;
					font-weight: bold;
				}

				.text {
					padding: 20rpx;
					text-indent: 50rpx;
				}

				.call-item {
					padding: 0 20rpx 40rpx 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.call-img {
						width: 30rpx;
					}
				}
			}
		}

		.bottom {}
	}
</style>